#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 510;
int a[N][N], f[N][N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= i; ++j) {
			cin >> a[i][j];
			f[i][j] = a[i][j];
		}
	}
	for (int i = n; i >= 1; --i) {
		for (int j = i; j >= 1; --j) {
			f[i - 1][j] += max(f[i][j], f[i][j + 1]);
		}
	}
	cout << f[1][1];
	return 0;
}